var userTreeObjx;
$(function(){
	var usettingx = {
		    view:{
		    	dblClickExpand: false
		    },
			check: {
			    enable: true,
			    chkboxType :{ "Y" : "s", "N" : "s" }

			},
			async : {
				enable : true,
				url : "business/component!ztreeall",
				autoParam : ["id=bean.id"],
				otherParam:{}
			   // dataFilter: filter
			},
			callback: {
				onExpand: zTreeOnExpand,
				beforeCheck:zTreeBeforeCheck
			}

		};

		var UzNodesx = [
		              {
		            	  name : "北方特种能源有限公司西安庆华公司",
		          		  open : true,
		          		  nocheck:true,
		          		  id:"root",
		          		  isParent:true
		              }              
		];
    userTreeObjx = $.fn.zTree.init($("#usertree") , usettingx ,UzNodesx);
	var root = userTreeObjx.getNodes();
	userTreeObjx.expandNode(root[0]);
	$("#saveBtn").bind("click",function(){
		var nodes = userTreeObjx.getCheckedNodes(true);
		if(nodes.length==0){
			alert("请选择至少一个用户！");
			return;
		}
		var datastr ="bean.name="+$("#guname").val()+"&";
		for(var i=0;i<nodes.length;i++){
			var n = nodes[i];
			datastr+="bean.users["+i+"]="+n.id+"&";		
		}		
		datastr+="bean.owner.username="+owner;
		doSubmit(fileServer+"groupuser/group-user!"+beanId?"create":"update",datastr,function(){
			createNotify("保存完成!");							
		});
	});
});

function zTreeBeforeCheck(treeId, treeNode) {
    return !treeNode.isParent;
};

function zTreeOnExpand(event, treeId, treeNode) {
    var cld = treeNode.children;
    for(var i=0;i<cld.length;i++){
    	var cnode = cld[i];
    	if($.inArray(cnode.id,users))
    	userTreeObjx.checknode(cnode,true,true);
    }
};
